// DlgIOParam.cpp : implementation file
//

#include "stdafx.h"
#include "DlgIOParam.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CDlgIOParam dialog


CDlgIOParam::CDlgIOParam(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgIOParam::IDD, pParent)
	, m_iSignalType(0)
{
	//{{AFX_DATA_INIT(CDlgIOParam)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgIOParam::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgIOParam)
	// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgIOParam, CDialog)
	//{{AFX_MSG_MAP(CDlgIOParam)
	ON_EN_CHANGE(IDC_EDIT_GasPort, OnChangeEDITGasPort)
	ON_EN_CHANGE(IDC_EDIT_LaserPort, OnChangeEDITLaserPort)
	ON_EN_CHANGE(IDC_EDIT_RedLightPort, OnChangeEDITRedLightPort)
	ON_EN_CHANGE(IDC_EDIT_Cylinder, OnChangeEDITCylinder)
	ON_EN_CHANGE(IDC_EDIT_GreenLight, OnChangeEDITGreenLight)

	ON_EN_CHANGE(IDC_EDIT_Ready, OnChangeEDITReady)
	ON_EN_CHANGE(IDC_EDIT_Running, OnChangeEDITRunning)
	ON_EN_CHANGE(IDC_EDIT_Warnning, OnChangeEDITWarnning)
	ON_EN_CHANGE(IDC_EDIT_Feed, OnChangeEDITFeed)
	ON_EN_CHANGE(IDC_EDIT_Unloading, OnChangeEDITUnLoading)

	ON_EN_CHANGE(IDC_EDIT_INSTOPPORT, OnChangeEditInStopPort)
	ON_EN_CHANGE(IDC_EDIT_INUnloadDonePORT, OnChangeEditUnloadDonePort)
	ON_EN_CHANGE(IDC_EDIT_INISHAVEMETALPORT, OnChangeEditIsHaveMetalPort)
	
	ON_EN_CHANGE(IDC_EDIT_INFeedPort, OnChangeEditInFeedPort)
	ON_EN_CHANGE(IDC_EDIT_DoorProtectPort, OnChangeEditDoorProtectPort)
	
	
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgIOParam message handlers

void CDlgIOParam::OnOK() 
{
	// TODO: Add extra validation here
	CString strIO;
	GetDlgItemText(IDC_EDIT_LaserPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iLaserOn = iIOPort;

	GetDlgItemText(IDC_EDIT_RedLightPort,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRedLightOn = iIOPort;

	GetDlgItemText(IDC_EDIT_GasPort,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGasOn = iIOPort;

	GetDlgItemText(IDC_EDIT_Cylinder,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iCylinder = iIOPort;

	GetDlgItemText(IDC_EDIT_GreenLight,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGreenLight = iIOPort;

	GetDlgItemText(IDC_EDIT_Ready,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iReady = iIOPort;

	GetDlgItemText(IDC_EDIT_Running,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRunning = iIOPort;

	GetDlgItemText(IDC_EDIT_INSTOPPORT,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInStopPort = iIOPort;

	GetDlgItemText(IDC_EDIT_INUnloadDonePORT,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iUnloadDonePort = iIOPort;

	GetDlgItemText(IDC_EDIT_INISHAVEMETALPORT,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_isHaveMetal = iIOPort;

	GetDlgItemText(IDC_EDIT_INFeedPort,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInFeedPort = iIOPort;

	GetDlgItemText(IDC_EDIT_DoorProtectPort,strIO);
	iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iDoorProtectPort = iIOPort;
	CDialog::OnOK();
}

BOOL CDlgIOParam::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	CString strIO;
	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iLaserOn);
	SetDlgItemText(IDC_EDIT_LaserPort,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRedLightOn);
	SetDlgItemText(IDC_EDIT_RedLightPort,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGasOn);
	SetDlgItemText(IDC_EDIT_GasPort,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iCylinder);
	SetDlgItemText(IDC_EDIT_Cylinder,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iReady);
	SetDlgItemText(IDC_EDIT_Ready,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGreenLight);
	SetDlgItemText(IDC_EDIT_GreenLight,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRunning);
	SetDlgItemText(IDC_EDIT_Running,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iWarnning);
	SetDlgItemText(IDC_EDIT_Warnning,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iFeed);
	SetDlgItemText(IDC_EDIT_Feed,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iUnloading);
	SetDlgItemText(IDC_EDIT_Unloading,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInStopPort);
	SetDlgItemText(IDC_EDIT_INSTOPPORT,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iUnloadDonePort);
	SetDlgItemText(IDC_EDIT_INUnloadDonePORT,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_isHaveMetal);
	SetDlgItemText(IDC_EDIT_INISHAVEMETALPORT,strIO);	

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInFeedPort);
	SetDlgItemText(IDC_EDIT_INFeedPort,strIO);

	strIO.Format(_T("%d"),((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iDoorProtectPort);
	SetDlgItemText(IDC_EDIT_DoorProtectPort,strIO);

	if (CDlgLogin::gAuthority > 2)
	{
		GetDlgItem(IDC_EDIT_LaserPort)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Ready)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_RedLightPort)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Running)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_GasPort)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Warnning)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Cylinder)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Feed)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_GreenLight)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_Unloading)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_INSTOPPORT)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_INUnloadDonePORT)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_INFeedPort)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_INISHAVEMETALPORT)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_DoorProtectPort)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_EDIT_LaserPort)->EnableWindow();
		GetDlgItem(IDC_EDIT_Ready)->EnableWindow();
		GetDlgItem(IDC_EDIT_RedLightPort)->EnableWindow();
		GetDlgItem(IDC_EDIT_Running)->EnableWindow();
		GetDlgItem(IDC_EDIT_GasPort)->EnableWindow();
		GetDlgItem(IDC_EDIT_Warnning)->EnableWindow();
		GetDlgItem(IDC_EDIT_Cylinder)->EnableWindow();
		GetDlgItem(IDC_EDIT_Feed)->EnableWindow();
		GetDlgItem(IDC_EDIT_GreenLight)->EnableWindow();
		GetDlgItem(IDC_EDIT_Unloading)->EnableWindow();
		GetDlgItem(IDC_EDIT_INSTOPPORT)->EnableWindow();
		GetDlgItem(IDC_EDIT_INUnloadDonePORT)->EnableWindow();
		GetDlgItem(IDC_EDIT_INFeedPort)->EnableWindow();
		GetDlgItem(IDC_EDIT_INISHAVEMETALPORT)->EnableWindow();
		GetDlgItem(IDC_EDIT_DoorProtectPort)->EnableWindow();
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgIOParam::OnChangeEDITGasPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_GasPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGasOn = iIOPort;
	
}

void CDlgIOParam::OnChangeEDITLaserPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_LaserPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iLaserOn = iIOPort;	
}

void CDlgIOParam::OnChangeEDITRedLightPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_RedLightPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRedLightOn = iIOPort;	
}

void CDlgIOParam::OnChangeEDITCylinder() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Cylinder,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iCylinder = iIOPort;	
}

void CDlgIOParam::OnChangeEDITGreenLight() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_GreenLight,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iGreenLight = iIOPort;	
}

void CDlgIOParam::OnChangeEDITReady() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Ready,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iReady = iIOPort;	
}

void CDlgIOParam::OnChangeEDITRunning() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Running,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iRunning = iIOPort;	
}

void CDlgIOParam::OnChangeEDITWarnning() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Warnning,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iWarnning = iIOPort;	
}

void CDlgIOParam::OnChangeEDITFeed() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Feed,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iFeed = iIOPort;	
}

void CDlgIOParam::OnChangeEDITUnLoading() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_Unloading,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iUnloading = iIOPort;	
}

void CDlgIOParam::OnChangeEditInStopPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_INSTOPPORT,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInStopPort = iIOPort;	
}


void CDlgIOParam::OnChangeEditIsHaveMetalPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_INISHAVEMETALPORT,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_isHaveMetal = iIOPort;	
}
void CDlgIOParam::OnChangeEditUnloadDonePort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_INUnloadDonePORT,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iUnloadDonePort = iIOPort;	
}


void CDlgIOParam::OnChangeEditInFeedPort() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strIO;
	GetDlgItemText(IDC_EDIT_INFeedPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iInFeedPort = iIOPort;	
}

void CDlgIOParam::OnChangeEditDoorProtectPort()
{
	CString strIO;
	GetDlgItemText(IDC_EDIT_DoorProtectPort,strIO);
	int iIOPort = (int)(CTool::CStringToDouble(strIO));
	((CDlgSysParam*)GetParent())->m_param.m_ioPara.m_iDoorProtectPort = iIOPort;	
}

void CDlgIOParam::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	OnOK();
}
